package com.threeox.httplibrary.builder;

import com.threeox.httplibrary.request.PostFormRequest;
import com.threeox.httplibrary.request.RequestCall;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @ClassName: PostFormBuilder
 *
 * @Description: Todo(Post请求方式构造器)
 *
 * @author 赵屈犇
 *
 * @date 创建时间:2016/12/21 11:29
 *
 * @version 1.0
 */
public class PostFormBuilder extends OkHttpRequestBuilder<PostFormBuilder>
{
    private List<FileInput> files = new ArrayList<FileInput>();

    @Override
    public RequestCall build()
    {
        return new PostFormRequest(url, tag, params, headers, files,id).build();
    }

    public PostFormBuilder files(String key, Map<String, File> files)
    {
        for (String filename : files.keySet())
        {
            this.files.add(new FileInput(key, filename, files.get(filename)));
        }
        return this;
    }

    public PostFormBuilder addFile(String name, String filename, File file)
    {
        files.add(new FileInput(name, filename, file));
        return this;
    }

    public static class FileInput
    {
        public String key;
        public String filename;
        public File file;

        public FileInput(String name, String filename, File file)
        {
            this.key = name;
            this.filename = filename;
            this.file = file;
        }

        @Override
        public String toString()
        {
            return "FileInput{" +
                    "key='" + key + '\'' +
                    ", filename='" + filename + '\'' +
                    ", file=" + file +
                    '}';
        }
    }

}
